from django.contrib import admin
# Register your models here.
from django.db import transaction
from django.urls import reverse
from .models import *
from import_export import resources
from import_export.admin import ImportExportModelAdmin, ImportExportActionModelAdmin
import datetime


# Register your models here.

class Proxyvideo(resources.ModelResource):
    class Meta:
        model = Video


@admin.register(Video)
class VideoAdmin(admin.ModelAdmin):
    resource_class = Proxyvideo
    #video_class = Proxyvideo
    list_display = ('id','video')
    # 分页显示，一页的数量
    list_per_page = 10
    actions_on_top = True

class videoInline(admin.TabularInline):
    model = Video
    extra = 1


class ProxyResource(resources.ModelResource):
    class Meta:
        model = ProcessTask


@admin.register(ProcessTask)
class ProcessTaskAdmin(ImportExportActionModelAdmin):
    resource_class = ProxyResource
    
    list_display =('id','name','video_type','vender','user','passwd','ip_number','stream_port','idle_model','channel','create_time')
    # 需要搜索的字段
    search_fields = ('name',)
    
    #过滤框
    list_filter = ('create_time',)
    # 分页显示，一页的数量
    list_per_page = 10
    
    # 可编辑选项 设定
    list_editable = ('name','video_type','vender','user','passwd','ip_number','stream_port','idle_model','channel')
    
    #时间等级设定 
    date_hierarchy = 'create_time'
    
    # 视频文件 列表上传设定
    inlines = [
        videoInline,
    ]

    # 按钮置顶设定 
    actions_on_top = True
    
    # 添加编辑区域分界设定 
    fieldsets = [
        ('通道基本信息设置', {'fields': ['name','idle_model','channel']}),
        ('摄像头信息设置', {'fields': ['video_type','vender','user','passwd','ip_number','stream_port']}),
    ]
    
    # 按钮属性和功能设定
    @transaction.atomic
    def test(self, request, queryset):
        pass

    '''
    actions = ['test','make_copy']
    test.short_description = '测试按钮'
    '''


class ProxyTaskPlan(resources.ModelResource):
    class Meta:
        model = TaskPlan


@admin.register(TaskPlan)
class taskPlanAdmin(ImportExportActionModelAdmin):
    resource_class = ProxyTaskPlan
    
    list_display =('id','name','cycle_model','cycle_week','start_time','finish_time')
    list_per_page = 10
    actions_on_top = True
    # 可编辑选项 设定
    list_editable = ('cycle_model','cycle_week','start_time')
    actions_on_top = True


    def custom_button(self, request, queryset):
        pass
